﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// This filter is used to enhance the colors of a pic.
    /// i.e. to give them more intensity by adding a value
    /// </summary>
    public class EnhanceColors : BaseImageFilter
    {
        protected int m_nEnhance = 10;
        protected int m_nFactor = 1;

        /// <summary>
        /// Default constructor
        /// </summary>
        public EnhanceColors()
        {
        }

        /// <summary>
        /// primary constructor, specify properties directly
        /// </summary>
        /// <param name="_nEnhance"></param>
        /// <param name="_nFactor"></param>
        public EnhanceColors(int _nEnhance, int _nFactor)
        {
            this.m_nEnhance = _nEnhance;
            this.m_nFactor = _nFactor;
        }

        /// <summary>
        /// used by clone to create a deep copy
        /// </summary>
        /// <param name="_enhanceColors"></param>
        internal EnhanceColors(EnhanceColors _enhanceColors)
        {
            this.m_nEnhance = _enhanceColors.m_nEnhance;
            this.m_nFactor = _enhanceColors.m_nFactor;
        }

        /// <summary>
        /// Gets or sets of this pic should be ENHANCED or "DISHANCED"
        /// </summary>
        public int Enhance
        {
            get { return m_nEnhance; }
            set { m_nEnhance = value; }
        }

        /// <summary>
        /// Gets or sets a factor for enhancing
        /// </summary>
        public int Factor
        {
            get { return m_nFactor; }
            set { m_nFactor = value; }
        }

        /// <summary>
        /// Executes this filter
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmap = _bitmap;
            Color colorLeft = Color.Transparent;

            int nHeight = bitmap.Height;
            int nWidth = bitmap.Width;

            int x = 0;
            int y = 0;

            Color color = Color.Transparent;
            for (y = 0; y < nHeight; y++)
            {
                for (x = 0; x < nWidth; x++)
                {
                    colorLeft = bitmap.GetPixel(x, y);
                    color = ColorFunctions.EnhanceColor(colorLeft, m_nEnhance, m_nFactor);
                    bitmap.SetPixel(x, y, color);
                }
            }
            return _bitmap;
        }

        /// <summary>
        /// Use this to create a deep copy
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new EnhanceColors(this);
        }
    }
}

